import * as actionTypes from './constants'
import axios from 'axios'

export const increaseCountAction = (value) => ({
  type: actionTypes.INCREASE_COUNT,
  value
})

export const decreaseCountAction = (value) => ({
  type: actionTypes.DECREASE_COUNT,
  value
})

export const changeBannersAction = (banners) => ({
  type: actionTypes.CHANGE_BANNERS,
  banners
})

export const fetchHotSuggestsAction = () => {
  // 如果是一个普通的action，需要返回一个对象
  // 由于接口数据时异步的，所以这里对象中是拿不到数据的
  // 所以这里要返回一个函数，返回函数需要中间件redux-thunk进行增强
  return (dispatch, getState) => {
    axios.get("http://codercba.com:1888/api/home/hotSuggests").then(res => {
      const list = res.data.data.map(item => item.tagText.text)
      dispatch(changeBannersAction(list))
    })
  }
   
}